﻿using AdverseEventReportSystem.Model;
using AdverseEventReportSystem.Service;
using AdverseEventReportSystem.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using AdverseEventReportSystem.BLL;
using AdverseEventReportSystem.Core;

namespace AdverseEventReportSystem.Web.Controllers
{
    public class HomeController : BaseController
    {
        /// <summary>
        /// Index
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 桌面
        /// </summary>
        /// <returns></returns>
        public ActionResult Desktop()
        {
            return View();
        }

        /// <summary>
        /// 初始化菜单
        /// </summary>
        /// <returns></returns>
        public ActionResult InitMenu()
        {
            List<MenuInfo> menuList = MenuManager.GetMenu(loginUser.Personnel_id, 3);
            return JsonDate(menuList);
        }

        /// <summary>
        /// 获取登录用户信息
        /// </summary>
        /// <returns></returns>
        public ActionResult GetLoginUser()
        {
            return JsonDate(loginUser);
        }

        /// <summary>
        /// 切换病区
        /// </summary>
        /// <returns></returns>
        public ActionResult ChangeDept()
        {
            ViewBag.CurrDepCode = loginUser.CurrDepCode;
            return View();
        }

        /// <summary>
        /// 切换病区保存
        /// </summary>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public ActionResult ChangeDeptSave(string code,string name)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                loginUser.CurrDepCode = code;
                loginUser.CurrDepName = name;
                LoginManager.SetLoginCookie(loginUser);
            }
            catch(Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return JsonDate(resultInfo); ;
        }

        /// <summary>
        /// 获取不良事件数据
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAdverseEventData()
        {
            string dateType = WebUtils.GetString("dateType");
            OperateResult resultInfo = AdverseEventManager.GetDeskAdverseEventData(dateType);
            return JsonDate(resultInfo);
        }

        /// <summary>
        /// 查询ECharts
        /// </summary>
        /// <returns></returns>
        public ActionResult EChartsSearch()
        {
            var title = "";
            var xAxisTitle = "科室";
            var yAxisTitle = "床位数";
            var legendData = new string[1] { "" };
            var seriesData = new List<object>();
            var xAxisData = new List<string>();
            Random rd = new Random();
            for (int i = 0; i < 70; i++)
            {
                xAxisData.Add("N" + (i + 1) + "病区");

                seriesData.Add(new { name = "", value = 0 });
            }
            var result = new { Code = 1, D = new { title = title, xAxisTitle = xAxisTitle, yAxisTitle = yAxisTitle, legendData = legendData, seriesData = seriesData, xAxisData = xAxisData} };

            return JsonDate(result);
        }
    }
}